<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>axios</title>
</head>
<body>

    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

    <script>
        const url = 'https://www.imooc.com/api/http/search/suggest?words=js';

        /*axios(url,{
            method:'post',
            headers:{
                // 'Content-Type':'application/x-www-form-urlencoded'
                'Content-Type':'application/json'
            },
            // 请求头携带的数据
            params:{username:'swk'},
            // 请求体携带的数据
            data:{age:5000},
            // data:'age=5000'
            timeout:10,
        }).then(response =>{
            console.log(response);
        }).catch(err =>{
            console.log(err);
        });*/

        // get请求
        /*axios.get(url,{
            params:{
                username:'suk'
            }
        }).then(response =>{
            console.log(response);
        }).catch(err =>{
            console.log(err);
        })*/

        // post请求
        axios.post(url,'username="swk"').then(response =>{
            console.log(response);
        }).catch(err =>{
            console.log(err);
        })
    </script>
</body>
</html>